package com.bw.home.adpter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bw.home.R
import com.bw.home.databinding.ItemRecommendBinding
import com.bw.home.entity.SimpleVideoEntity

class RecommendAdapter(val context: Context, val list: List<SimpleVideoEntity>) :
    RecyclerView.Adapter<RecommendAdapter.RecommendViewHolder>() {
    class RecommendViewHolder(val binding: ItemRecommendBinding) :
        RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecommendViewHolder {
        val view = ItemRecommendBinding.inflate(LayoutInflater.from(context), parent, false)
        return RecommendViewHolder(view)
    }

    override fun onBindViewHolder(holder: RecommendViewHolder, position: Int) {
        holder.binding.setVariable(R.layout.item_recommend, list[position])

        val entity = list.get(position)
        Glide.with(context).load(entity.avatar_url).into(holder.binding.ivPrimaryimgeRecommend)
        holder.binding.tvTitleRecommend.text = entity.title


    }

    override fun getItemCount(): Int {
        return list.size
    }
}